//
//  MeiFView.m
//  MyProject
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 蓝鸥0825. All rights reserved.
//

#import "MeiFView.h"
#import "MeiFCollectionCell.h"
#import "MeiFsecController.h"
#import "UIImageView+WebCache.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@implementation MeiFView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}



- (void)create{
    
    self.layOut = [[UICollectionViewFlowLayout alloc] init];
    self.layOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:self.layOut];
    self.collection.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.collection];
    [self addSubview:self.collection];
    self.collection.dataSource = self;
    self.collection.delegate = self;
    [self.collection registerClass:[MeiFCollectionCell class] forCellWithReuseIdentifier:@"reuse"];
    
    self.collection.bounces = NO;
 
   
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MeiFCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    [cell.image sd_setImageWithURL:self.array[indexPath.row][@"contents"][@"image"][@"url"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    cell.label.text = self.array[indexPath.row][@"contents"][@"title"];
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    MeiFsecController *mfc = [[MeiFsecController alloc] init];
    [self.VC.navigationController pushViewController:mfc animated:YES];
    mfc.str = self.array[indexPath.row][@"url"];
    mfc.array = self.array;
    [mfc release];
 
}




@end
